﻿;(function(){
  'use strict';
  angular.module('controllers.workOrderData.auditData')
  .controller('passRateController',passRateController);
  function passRateController($scope,passRateService,auditDataService,$timeout,COREDATA,CoreLoading,workOrderDataService){
  	$scope.flag = {
  		state: true,
  		show: 'view',
  		arrow: false
  	};
  	$scope.initQuery = function(){
		auditDataService.queryWorkDataType(function(res){
			$scope.workDataTypes = res.data;
			$scope.search();
		});
	};
	$scope.formPrefix = COREDATA.FORMPREFIX+'workOrderData/auditData/export';
  	//页面查询项绑定对象
  	var date = new Date();
  	var year = date.getFullYear();
  	var month = date.getMonth();
  	$scope.params = {
  		startTime: new Date(year,month-6),
  		endTime: new Date(year,month-1),
  		changeTypeCode: '1',
  		workOrderTypeCode : '15601',
  		timeType: '3'
  	};
	var myEcharts = echarts.init(document.getElementById('doc'));
  	//查询
  	$scope.search = function(){
		var changeTypeName = $scope.params.changeTypeCode === '1' ? '各科室' : '各系统';
		$scope.flag.state = !$scope.flag.state;
		var option;
		if(!$scope.flag.state){
			$scope.send = passRateService.fmtSendData($scope.params);
			var timeTitle = passRateService.fmtDateTitle($scope.send);
			//标题:时间+各系统或科室+工单类型+审计通过率趋势;
			$scope.name = auditDataService.getName($scope.params.workOrderTypeCode,$scope.workDataTypes);
			$scope.send.title = timeTitle + changeTypeName + $scope.name + '审计通过率趋势';
			CoreLoading.setState(true);
  			passRateService.passRateQuery($scope.send,function(res){
			if(res.state === '10000' && res.data.length >= 1){
				myEcharts.clear();
				$scope.items = res.data;
				$scope.title = $scope.send.title;
				$scope.item = workOrderDataService.getArrayData(res.data);
				option = workOrderDataService.getEchartsLineData($scope.item,res.data,$scope.title,'percentage');
				//echarts图提示信息
				option.tooltip.formatter = workOrderDataService.getFormatterFn('%');
				option.yAxis[0].axisLabel = { formatter: '{value} %' };
				myEcharts.setOption(option);
				$scope.outData = workOrderDataService.exportView(myEcharts,$scope.send);
				$scope.flag.arrow = true;
				$scope.flag.show = 'view';
			}else if(res.data.length === 0){
				workOrderDataService.queryNoDataOrError($scope.flag,'查询无数据');
			}else {
				workOrderDataService.queryNoDataOrError($scope.flag,'查询错误');
			}
			CoreLoading.setState(false);
		 });
		}
	};
		//监听表单,当表单有错时,禁止查询
		$scope.$watch('myForm.$invalid', function(newValue) {
			newValue ? $scope.flag.arrow = false : $scope.flag.arrow = true;
		});
  }
  passRateController.$inject = ['$scope','passRateService','auditDataService','$timeout','COREDATA','CoreLoading','workOrderDataService'];
})();